﻿<%@ Page Title="" Language="C#" MasterPageFile="~/WebmasterTool/Admin.Master" AutoEventWireup="true"
    CodeBehind="Categories.aspx.cs" Inherits="Framework.WebmasterTool.Categories" %>

<%@ Register Src="../Controls/simpleImageUploadUserControl/SimpleImageUpload.ascx"
    TagName="SimpleImageUpload" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%= btnDelete.ClientID %>").live("click", function () {
                var callFrom = $(this);
                jConfirm('Chắc chắn xoá?', 'Digisky Confirm Dialog',
                            function (r) {
                                if (r) {
                                    __doPostBack(callFrom.attr('name').replace(/_/g, '$'), '');
                                }
                            });
                return false;
            });
            //multiupload
            var num = 0;
            $(function () {
                $('#<%= PhotoFile.ClientID %>').MultiFile({
                    afterFileAppend: function (element, value, master_element) {
                        $(".MultiFile-label:last").children(":last").after(
                        "<br/><table><tr><td>Tiêu đề: </td><td><input id='Title" + num + "' type='text' name='Title" + num + "' style='width:250px' /></td></tr>" +
                        "<tr><td>Tiêu đề(en): </td><td><input id='Title_en" + num + "' type='text' name='Title_en" + num + "' style='width:250px' /></td></tr>" +
                        "<tr><td>Alt ảnh: </td><td><input id='Alt" + num + "' type='text' name='Alt" + num + "' style='width:250px' /></td></tr></table>"
                        );
                        num++;
                        $("#<%= hdfNumImage.ClientID %>").val(num);
                    },
                    accept: 'gif|jpg|jpeg|png|bmp',
                    STRING: {
                        remove: '[Xoá]',
                        denied: 'Chỉ chấp nhận định dạng file ảnh. Không chấp nhận kiểu file $ext',
                        duplicate: 'Đã tồn tại file: \n$file'
                    }
                });
            });
            //delete image cate
            $("a[ImageID]").live("click", function () {
                var ImageID = $(this).attr("ImageID");
                jConfirm('Chắc chắn xoá?', 'Digisky Confirm Dialog', function (r) {
                    if (r) {
                        $.ajax({
                            type: "POST",
                            url: "Categories.aspx/DeleteImageCate",
                            data: JSON.stringify({ ImageID: ImageID }),
                            contentType: "application/json; charset=utf-8",
                            async: false,
                            dataType: "json",
                            success: function (response) {
                                $("table[ImageID=" + ImageID + "]").remove();
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                jAlert(thrownError);
                            }
                        });
                    }
                });
            });
            //jeditable
            $(".jeditable").live("hover", function () {
                $(this).editable(function (value, settings) {
                    var ImageID = $(this).attr("ImageID");
                    var NewValue = value;
                    var Attribute = $(this).attr("attribute");
                    $.ajax({
                        type: "POST",
                        url: "Categories.aspx/EditAttributeImageCate",
                        data: JSON.stringify({ ImageID: ImageID, NewValue: NewValue, Attribute: Attribute }),
                        contentType: "application/json; charset=utf-8",
                        async: false,
                        dataType: "json",
                        success: function (response) {
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            jAlert(thrownError);
                        }
                    });
                    return value;
                },
                {
                    event: 'dblclick',
                    type: 'text',
                    select: true,
                    width: '150',
                    loadtype: 'POST',
                    cancel: 'Huỷ',
                    submit: 'Lưu',
                    tooltip: 'double click để thay đổi'
                });
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ctlCaption" runat="Server">
    Quản lý danh mục
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageContent" runat="Server">
    <asp:Label ID="lblPermissionMessage" runat="server" Font-Bold="true" ForeColor="Red"
        Text="Tài khoản không có quyền truy cập vào trang này" Visible="false"></asp:Label>
    <asp:Panel ID="Panel1" runat="server" Visible="true">
        <asp:HiddenField ID="hdfNumImage" runat="server" Value="0" />
        <table border="0" cellpadding="0" cellspacing="10" width="100%">
            <tr>
                <td valign="top" colspan="2" align="center">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" Font-Bold="true" DisplayMode="List"
                        ValidationGroup="Categories" />
                    <asp:Label runat="server" ID="lblMsg" ForeColor="red" Font-Bold="true"></asp:Label>
                </td>
            </tr>
            <tr>
                <td valign="top" style="padding: 10px; background: #f5f5f5; border: solid 1px #ccc;
                    width: 300px">
                    <asp:TreeView ID="trvCategories" runat="server" ImageSet="Arrows" Font-Names="verdana"
                        Font-Size="12px" Width="280px">
                        <Nodes>
                            <asp:TreeNode Text="All Items" SelectAction="Expand" Value="All Items" />
                        </Nodes>
                        <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px"
                            Font-Bold="True"></SelectedNodeStyle>
                        <ParentNodeStyle Font-Bold="False" ForeColor="#555555" />
                        <RootNodeStyle Font-Bold="true" />
                        <NodeStyle Font-Names="Verdana" Font-Size="12px" ForeColor="Black" HorizontalPadding="5px"
                            NodeSpacing="0px" VerticalPadding="5px"></NodeStyle>
                        <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD"></HoverNodeStyle>
                    </asp:TreeView>
                </td>
                <td valign="top">
                    <table border="0" cellpadding="2" align="center" style="padding: 10px; background: #f5f5f5;
                        border: solid 1px #ccc; width: 100%">
                        <tr>
                            <td align="right" style="width: 100px;">
                                <b>Loại danh mục: </b>
                            </td>
                            <td>
                                <asp:DropDownList ID="ddlCategories" runat="server" DataTextField="Title" DataValueField="CateID"
                                    Width="250px">
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <b>Tên danh mục: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtCateName" runat="server" Width="250" MaxLength="700"></asp:TextBox>
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="txtCateName"
                                    ErrorMessage="Chưa nhập tên danh mục" Display="Dynamic" ValidationGroup="Categories">*</asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr runat="server" visible="true">
                            <td align="right">
                                <b>Tên(en): </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtCateName_en" runat="server" Width="250" MaxLength="700"></asp:TextBox>
                            </td>
                        </tr>
						<tr>
                            <td align="right">
                                <b>Link ngoài: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtExternalLink" runat="server" Width="250" MaxLength="700"></asp:TextBox><br />
                                <asp:CheckBox ID="chkBlankExternalLink" runat="server" Text="Mở trang mới"/>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Chi tiết: </b>
                            </td>
                            <td>
                                <CKEditor:CKEditorControl ID="txtDesciption" runat="server" UIColor="#CED9F3" Width="300"
                                    Height="200" Toolbar="Basic" BasePath="/Plugins/Ckeditor" ContentsCss="/Plugins/Ckeditor/contents.css"
                                    TemplatesFiles="/Plugins/Ckeditor/plugins/templates/templates/default.js">
                                </CKEditor:CKEditorControl>
                            </td>
                        </tr>
                        <tr runat="server" visible="true">
                            <td valign="middle" align="right">
                                <b>Chi tiết(en): </b>
                            </td>
                            <td>
                                <CKEditor:CKEditorControl ID="txtDesciption_en" runat="server" UIColor="#CED9F3"
                                    Width="300" Height="200" Toolbar="Basic" BasePath="/Plugins/Ckeditor" ContentsCss="/Plugins/Ckeditor/contents.css"
                                    TemplatesFiles="/Plugins/Ckeditor/plugins/templates/templates/default.js">
                                </CKEditor:CKEditorControl>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Meta Description: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtMetaDescription" runat="server" Width="250" Height="100" TextMode="MultiLine"
                                    Rows="3" MaxLength="700"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Meta Keywords: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtMetaKeywords" runat="server" Width="250" Height="100" TextMode="MultiLine"
                                    Rows="3" MaxLength="700"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Meta Title: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtMetaTitle" runat="server" Width="250" Height="100" TextMode="MultiLine"
                                    Rows="3" MaxLength="700"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Meta khác và script: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtMetaOrther" runat="server" Width="250" Height="100" TextMode="MultiLine"
                                    Rows="3" MaxLength="700"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Image: </b>
                                <br />
                                <b>
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                        <ContentTemplate>
                                            <asp:CheckBox ID="chkWatermarkImage" runat="server" Text="Chèn chữ ký:" AutoPostBack="true"
                                                OnCheckedChanged="chkWatermarkImage_CheckedChanged" />
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </b>
                            </td>
                            <td>
                                <uc1:simpleimageupload id="siuCateImage" runat="server" cssclass="ImageUpload" autoopenimageeditpopupafterupload="true" />
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Alt ảnh: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtImageAlt" runat="server" Width="250"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <b>Sắp xếp:</b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtCateOrder" Font-Bold="true" runat="server" Width="138px" Text="0"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Chưa nhập vị trí cho danh mục"
                                    ControlToValidate="txtCateOrder" ValidationGroup="Categories" Display="Dynamic">*</asp:RequiredFieldValidator>
                                <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtCateOrder"
                                    Type="Integer" MinimumValue="0" MaximumValue="9999" ValidationGroup="Categories"
                                    ErrorMessage="Vị trí danh mục phải từ 0 đến 9999" Display="Dynamic">*</asp:RangeValidator>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <b></b>
                            </td>
                            <td>
                                <asp:CheckBox ID="chkIsActive" runat="server" Checked="true" Width="250" Text="Hiển thị menu trên" />
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <b></b>
                            </td>
                            <td>
                                <asp:CheckBox ID="chkIsActiveBottom" runat="server" Width="250" Text="Hiển thị menu dưới" />
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <b></b>
                            </td>
                            <td>
                                <asp:CheckBox ID="chkCateTop" runat="server" Width="250" Text="Danh mục nổi bật"
                                    Visible="true" />
                            </td>
                        </tr>
                        <tr>
                            <td valign="middle" align="right">
                                <b>Phân trang: </b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtPaging" Font-Bold="true" runat="server" Width="138px" Text="1"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Chưa nhập phân trang (số bài viết trên 1 trang) cho danh mục"
                                    ControlToValidate="txtPaging" ValidationGroup="Categories" Display="Dynamic">*</asp:RequiredFieldValidator>
                                <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtPaging"
                                    Type="Integer" MinimumValue="1" MaximumValue="100" ValidationGroup="Categories"
                                    ErrorMessage="Phân trang (số bài viết trên 1 trang) phải từ 1 đến 100" Display="Dynamic">*</asp:RangeValidator>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <b>Ngày tạo: </b>
                            </td>
                            <td>
                                <asp:Label ID="lblAddedDate" runat="server" Text="None"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <b>Người tạo: </b>
                            </td>
                            <td>
                                <asp:Label ID="lblAddedBy" runat="server" Text="None"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <b>Ngày update: </b>
                            </td>
                            <td>
                                <asp:Label ID="lblUpdatedDate" runat="server" Text="None"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <b>Người update: </b>
                            </td>
                            <td>
                                <asp:Label ID="lblUpdatedBy" runat="server" Text="None"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" colspan="2" valign="middle">
                                <asp:Button ID="btnSave" runat="server" Text="Lưu" ValidationGroup="Categories" Width="80px"
                                    OnClick="btnSave_Click"></asp:Button>
                                <asp:Button ID="btnNew" runat="server" Text="Thêm mới" Visible="false" Width="80px"
                                    OnClick="btnNew_Click"></asp:Button>
                                <asp:Button ID="btnDelete" runat="server" Text="Xóa" Visible="false" Width="80px"
                                    OnClick="btnDelete_Click"></asp:Button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td valign="top" colspan="2" align="center">
                    <div>
                        <div>
                            Upload nhiều ảnh cho category
                        </div>
                        <br />
                        <asp:CheckBox ID="chkWatermarkImage2" runat="server" Text="Chèn chữ ký" />
                        <br />
                        <asp:FileUpload runat="server" ID="PhotoFile" Width="217px" />
                    </div>
                    <div id="ListImage" style="margin-top: 20px;">
                        <asp:DataList ID="dtlImageCate" runat="server" RepeatDirection="Horizontal" RepeatColumns="3"
                            Width="100%">
                            <ItemTemplate>
                                <table imageid='<%# Eval("ImageID") %>' border="0" style="width: 260px;">
                                    <tr>
                                        <td bgcolor="white" align="center" style="width: 100%; height: 100px">
                                            <img style="border: solid 2px white; width: 150px; max-height: 90px;" src='<%# DGSFramework.Globals.ApplicationPath + "UserUpload/Categories/" + Eval("ImageUrl") %>'
                                                alt="" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" style="padding-top: 3pt; padding-bottom: 10px;" valign="top">
                                            <table>
                                                <tr>
                                                    <td align="left">
                                                        Tiêu đề:
                                                    </td>
                                                    <td class="jeditable" imageid='<%# Eval("ImageID") %>' attribute="title">
                                                        <%# Eval("Title")%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left">
                                                        Tiêu đề(en):
                                                    </td>
                                                    <td class="jeditable" imageid='<%# Eval("ImageID") %>' attribute="title_en">
                                                        <%# Eval("Title_en")%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left">
                                                        Alt ảnh:
                                                    </td>
                                                    <td class="jeditable" imageid='<%# Eval("ImageID") %>' attribute="alt">
                                                        <%# Eval("ImageAlt")%>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" align="center">
                                                        <a imageid='<%# Eval("ImageID") %>' style="cursor: pointer">[xóa]</a>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:DataList>
                    </div>
                </td>
            </tr>
        </table>
    </asp:Panel>
</asp:Content>
